<%@ page language="java"  pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body class="no-skin">
<!-- 以下为内容 -->
<div class="main-content1">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
		</script>
		<ul class="breadcrumb"  style="margin-top:10px">
			<li>
				<i class="ace-icon fa fa-home home-icon"></i>
				<a href="#">后台管理</a>						
			</li>
			<li class="active">任务管理</li>
		</ul>
			<!-- 路径结束 -->
	</div>

				<!-- /section:basics/content.breadcrumbs -->
	<div class="page-content">
		<div class="row">
		<div class="col-xs-12">
		<div class="tab-content no-border padding-24">
		<div id="faq-tab-1" class="tab-pane fade in active">
		<table width="100%" border="0">
				<tr>
					<td width="5%" align="right" nowrap="nowrap"><strong>应用：</strong></td>
					<td width="15%">
						<select id="clientCode" name="clientCode">
							<option value="">--请选择--</option>
							<c:forEach items="${appList}" var="app">
								<option value="${app.dictName}">${app.dictName}</option>
							</c:forEach>
						</select>
					</td>
				    <td width="5%" align="right" nowrap="nowrap"><strong>任务名称：</strong><input type="hidden" id="parentCode" value="${parentCode}"></td>
				    <td width="15%"><input name="jobName" type="text" id="jobName" maxlength="150" />    </td>
				    <td width="5%" align="right" nowrap="nowrap"><strong>任务分组：</strong></td>
				    <td width="15%"><input name="jobGroup" type="text" id="jobGroup" maxlength="150" />    </td>
				    <td align="right" nowrap="nowrap"  width="5%"><strong>状态：</strong></td>
				    <td align="left" width="10%" nowrap="nowrap">
				      <select name="jobStatus" id="jobStatus">
							<option selected="selected" value="">全部</option>
							<option value="1">正常</option>
							<option value="0">暂停</option>
					  </select>
					</td>
				    <td width="25%">
					    <button   class="btn btn-sm btn-info" type="button" onclick="initTable();">
					       <i class="ace-icon glyphicon glyphicon-search bigger-110"></i>查 询
						</button>
								
						<button class="btn btn-sm btn-warning" type="button" onclick="toAddJob();" >
						 	<i class="ace-icon glyphicon glyphicon-plus bigger-110"></i>新 增
						</button>
					</td>
			  </tr>
		</table>
	</div>
		
	
	<!--查询区域end-->
	<div id="faq-tab-1" class="tab-pane fade in active">
		<!--查询结果-->
		<div style="overflow-x:auto;  margin-top:10px">
			<table id="job_list_table" class="table table-striped table-bordered table-hover" style="margin:0; "  >
				<caption></caption>
				<thead>
					<tr>
						<th nowrap="nowrap" class="center">ScheduleID </th>
						<th nowrap="nowrap">系统</th>
						<th nowrap="nowrap">名称</th>
				        <th nowrap="nowrap" >分组</th>
				        <th nowrap="nowrap" >时间(cron表达式)</th>
				        <th nowrap="nowrap">状态</th>
				        <th nowrap="nowrap">操作</th>
				    </tr>
				</thead>
				<tbody>
		      	</tbody>
		   </table>
		</div>
	</div>
	</div>
	</div>
	</div>
	</div>
	</div>
	<script type="text/javascript">
	     jQuery(function($) {
			initTable();
		});
		function initTable(){
			$("#job_list_table").dataTable().fnDestroy();
			json={};
			json.showLineNuber=false;
			json.id="job_list_table";
		    json.url=contextPath+'/quartz/getAllJob.json';
		    json.param=[{"name" : "jobName","value" : $.trim($("#jobName").val())},
		                {"name" : "jobGroup","value" : $.trim($("#jobGroup").val())},
		                {"name" : "jobStatus","value" : $.trim($("#jobStatus").val())},
				{"name" : "clientCode","value" : $.trim($("#clientCode").val())}

		               ];
		    json.columns=[  {"mData" : "scheduleId","sWidth": "30px","sClass":"text-center"},
                {"mData" : "clientCode","sWidth": "100px","sClass":"text-center"},
							{"mData" : "jobFactName","sWidth": "100px","sClass":"text-center"},
								{"mData" : "jobGroup","sWidth": "100px","sClass":"text-center"},
								{"mData" : "cronExpression","sWidth": "100px","sClass":"text-center"},
								{"mData" : "jobStatus","sWidth": "50px","sClass":"text-center",
									"mRender" : function(data, type, row) 
								{
									if("1"==data){
										return '正常';
									}else if("0"==data){
										return '暂停';
									}else{
										return '错误';
									}
								}
								},
								{"mData" : "scheduleId","sWidth": "150px","sClass":"text-center",
								"mRender" : function(data, type, row) 
								{
									var manageStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:toEditJob('"+data+"')\">管理</a>";
									var stopStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:toStopJob('"+data+"')\">停止</a>";
									var startStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:toStartJob('"+data+"')\">启动</a>";
									var onceStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:executeOnce('"+data+"')\">立即执行</a>";
									var deleteStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:toDeleteJob('"+data+"');\">删除</a>";
									var detailStr="&nbsp;&nbsp;<a style=\"color:#428bca\" href=\"javascript:toDetail('"+data+"');\">明细</a>";
									if("0"==row.jobStatus){
										return manageStr+startStr+deleteStr+detailStr;
									}else if("1"==row.jobStatus){
										return manageStr+stopStr+onceStr+deleteStr+detailStr;
									}
								}
							}
					];
		    var oTable1=TableManaged(json).init();
		}
		
		
		//到新增页面
		function toAddJob(){
			window.location.href="../quartz/toJobAdd.htm";
		}
		
		//到修改页面
		function toEditJob(scheduleId){
			window.location.href=contextPath+"/quartz/toJobEdit.htm?scheduleId="+scheduleId;
		}
		
		
		//确认停止任务
		function toStopJob(scheduleId){
		$.Confirm('请确认是否停止该任务？','',function(){
	        	stopJob(scheduleId);
	    	});
		}
		
		function stopJob(scheduleId){
				 $.ajax({
		           url : contextPath + "/quartz/stopJob.json",
		           type : "post",
		           data : {"scheduleId":scheduleId},
		           async : false,
		           success : function(data){
		             var msg = eval("("+data+")");
		             $.Alert(msg.message,'',tojobList);
					   initTable();
		           },
		           error : function(){
		             //$.Alert("服务异常，请稍后尝试！");
		           }
		         });
		}
		
		//确认启动任务
		function toStartJob(scheduleId){
		$.Confirm('请确认是否启动该任务？','',function(){
	        	startJob(scheduleId);
	    	});
		}
		
		function startJob(scheduleId){
				 $.ajax({
		           url : contextPath + "/quartz/startJob.json",
		           type : "post",
		           data : {"scheduleId":scheduleId},
		           async : false,
		           success : function(data){
		             var msg = eval("("+data+")");
		             $.Alert(msg.message,'',tojobList);
					   initTable();
		           },
		           error : function(){
		             //$.Alert("服务异常，请稍后尝试！");
		           }
		         });
		}
		
		function tojobList(){
			location.href = contextPath+"/quartz/toJobList.htm";
		}
		
		function toDeleteJob(scheduleId){
			$.Confirm('请确认是否删除该定时任务？','',function(){
	        	deleteJob(scheduleId);
	    	});
		}
		
		function deleteJob(scheduleId){
		$.ajax({
		           url : contextPath + "/quartz/deleteJob.json",
		           type : "post",
		           data : {"scheduleId":scheduleId},
		           async : false,
		           success : function(data){
		             var msg = eval("("+data+")");
		             $.Alert(msg.message,'',tojobList);
		           },
		           error : function(){
		             //$.Alert("服务异常，请稍后尝试！");
		           }
		         });
		}
		 function executeOnce(scheduleId){
			 $.ajax({
				 url : contextPath + "/quartz/executeOnce.json",
				 type : "post",
				 data : {"scheduleId":scheduleId},
				 dataType:'json',
				 success : function(data){
					 if(data && data.status==200){
						 $.Alert("调度完毕，请注意查看执行日志");
					 }else{
						 $.Alert("未成功调度，请查看执行日志");
					 }
				 },
				 error : function(data){
					 $.Alert("未成功调度，请查看执行日志");
				 }
			 });
		 }

		function toDetail(sid){
			parent.mainTab.showTab(contextPath+"/quartz/toExecution.htm?scheduleId="+sid,'执行记录',true);
		}
	</script>
</body>
</html>
